package org.jiangnantaste.serviceimpl;

import java.sql.Connection;
import java.util.List;

import org.jiangnantaste.dao.ImageDao;
import org.jiangnantaste.daoimpl.ImageDaoImpl;
import org.jiangnantaste.database.DBConf;
import org.jiangnantaste.domain.Image;
import org.jiangnantaste.service.ImageService;

public class ImageServiceImpl implements ImageService{
	protected ImageDao dao = new ImageDaoImpl();
	@Override
	public boolean addImage(Image image) throws Exception {
		try (Connection connection = DBConf.initDB()){
			return dao.addImage(connection,image);
		}
	}

	@Override
	public boolean updateImage(Image image, String errorMessage)
			throws Exception {
		try (Connection connection = DBConf.initDB()){
			return dao.updateImage(connection,image);
		}
	}

	@Override
	public boolean deleteImage(long imageid) throws Exception {
		try (Connection connection = DBConf.initDB()){
			return dao.deleteImage(connection,imageid);
		}
	}

	@Override
	public List<Image> listAllImage() throws Exception {
		try (Connection connection = DBConf.initDB()){
			return dao.listAllImage(connection);
		}
	}

	@Override
	public Image findImageByImageId(long imageid) throws Exception {
		try (Connection connection = DBConf.initDB()){
			return dao.findImageByImageId(connection,imageid);
		}
	}

}
